package com.pattern.builder;

public class Main {

    public static void main(String[] args) {
//        new Director(new ConcreteBuilder1()).build();

        UserEntity build = UserEntity.newBuilder()
                .name("zhangsan")
                .age(15)
                .build();
        System.out.println(build.toString());

    }

}

class UserEntity {
    private String name;

    private Integer age;

    public UserEntity() {
    }

    private UserEntity(String name, Integer age) {
        this.name = name;
        this.age = age;
    }

    public static UserEntityBuilder newBuilder(){
        return new UserEntityBuilder();
    }

    @Override
    public String toString() {
        return "UserEntity{" +
                "name='" + name + '\'' +
                ", age=" + age +
                '}';
    }

    public static class UserEntityBuilder {

        private String name;

        private Integer age;

        public static UserEntityBuilder builder(){
            return new UserEntityBuilder();
        }

        public UserEntityBuilder name(String username) {
            this.name = username;
            return this;
        }

        public UserEntityBuilder age(Integer age) {
            this.age = age;
            return this;
        }

        public UserEntity build() {
            return new UserEntity(this.name, this.age);
        }

    }
}
